package com.example.babara.memo.utils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

/**
 * Created by babara on 2017/4/3.
 */

public class DatabaseHelper extends SQLiteOpenHelper{

    public static final String CREATE_MEMO = " create table memo(id integer primary key autoincrement," +
            "start_hour integer," +
            "start_main integer," +
            "memo_ring text," +
            "memo_card text," +
            "memo_repeat text," +
            "memo_scope text," +
            "memo_remark text)";

//    private final static String DATABASE_NAME = "memo.db";
//    private final static int DATABASE_VERSION = 1;
//    private final static String TABLE_NAME = "memo_table";
//    public final static String MEMO_ID = "memo_id";
//    public final static String START_HOUR = "start_hour";
//    public final static String SATART_MIN = "start_min";
//    public final static String MEMO_RING = "memo_ring";
//    public final static String MEMO_CARD = "memo_card";
//    public final static String MEMO_REPEAT = "memo_repeat";
//    public final static String MEMO_SCOPE = "memo_scope";
//    public final static String MEMO_REMARK = "memo_remark";
    private Context mContext;

    /**
     * 在SQLiteOpenHelper的子类当中，必须有该构造函数
     * @param context   上下文对象
     * @param name      数据库名称
     * @param factory
     * @param version   当前数据库的版本，值必须是整数并且是递增的状态
     */
    public DatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory,
                          int version) {
        //必须通过super调用父类当中的构造函数
        super(context, name, factory, version);
        mContext = context;
    }

    //该函数是在第一次创建的时候执行，实际上是第一次得到SQLiteDatabase对象的时候才会调用这个方法
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_MEMO);
        Toast.makeText(mContext, "生成表", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
        System.out.println("upgrade a database");
    }
}
